﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VSDBM.Code.dao;
using System.Data;

public partial class Visual_CRUD_Subtype_ListSubtype : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected void Excluindo(object sender, EventArgs e)
    {
        int id = int.Parse(GridSubtypes.SelectedRow.Cells[0].Text);
        VSDBM.Code.dto.Subtype obj = new VSDBM.Code.dto.Subtype();
        obj.id = id;
        VSDBM.Code.dto.User usuariologado = (VSDBM.Code.dto.User)HttpContext.Current.Session["usuariologado"];
        if (!(usuariologado.acessgroup == 1 || usuariologado.acessgroup == 2))
        {
            HttpContext.Current.Session["exception"] = "You are not authorized!";
            Response.Redirect("~/Visual/Errors/error.aspx");
            return;
        }
        SubtypeDAO.delete(obj);
        GridSubtypes.DataBind();
    }

    protected void search_click(object sender, EventArgs e)
    {
        String term = txtterm.Text;
        DataSet organismos = SubtypeDAO.selectforgridviewer(" AND UPPER(description) like '%" + term.ToUpper() + "%' OR  UPPER(org.name) like '%" + term.ToUpper() + "%' ");

        if (organismos.Tables[0].Rows.Count > 0)
        {
            GridSubtypes.DataSource = organismos.Tables[0];
            GridSubtypes.DataSourceID = null;
            GridSubtypes.DataBind();
        }
        else
        {
            Response.Redirect("../../../Visual/Errors/error.aspx?id=42");
        }
    }
}